using Habanero.BO;
using Habanero.BO.ClassDefinition;
using Habanero.UI.Base;
using Habanero.UI.Win;
using UseCaseManager.BO;

namespace UseCaseManager.UI
{
    /// <summary>
    /// A read-only grid control used for adding and editing Projects.
    /// </summary>
    public class ProjectsEditableGridControl : UserControlWin, IFormControl
    {
        private readonly IControlFactory _controlFactory;
        private readonly IEditableGridControl _projectGridControl;

        public ProjectsEditableGridControl(IControlFactory controlFactory)
        {
            _controlFactory = controlFactory;

            // Create the editable grid
            _projectGridControl = _controlFactory.CreateEditableGridControl();

            // Used to specify a custom UI def
            ProjectGridControl.Initialise(ClassDef.Get<Project>(), "default");

            // Load the collection of Projects.  You can set the criteria and order by values here.
            BusinessObjectCollection<Project> sampleCollection = Broker.GetBusinessObjectCollection<Project>("", "");
            ProjectGridControl.BusinessObjectCollection=sampleCollection;

            // Set this to true to enable the filters, then add your filters below (see commented out line)
            ProjectGridControl.FilterControl.Visible = false;
            //projectGridControl.FilterControl.AddStringFilterTextBox("", "");

            // Add the grid to the control so that it fills the control
            BorderLayoutManager layoutManager = _controlFactory.CreateBorderLayoutManager(this);
            layoutManager.AddControl(ProjectGridControl, BorderLayoutManager.Position.Centre);
        }

        public IEditableGridControl ProjectGridControl
        {
            get { return _projectGridControl; }
        }

        /// <summary>
        /// Called whenever the control is placed on a form by the menu system.  Put any initialisation
        /// code in here that must be run whenever the form is displayed.
        /// </summary>
        public void SetForm(IFormHabanero form) { }
    }
}